import java.util.List;

/*
    进程抽象
 */
public class Process {
    private PCB pcb;
    //占用IO总时间
    private int IOTimeZone;
    //占用CPU总时间
    private int CPUTimeZone;
    //所需总时间
    private int totalTimeZone;
    //程序计数器
    private int progressCount;
    //工作单元列表
    private List<WorkUnit> processWork;

    public Process(Process father,int IOTimeZone,int CPUTimeZone,List<WorkUnit> workUnitList,int processID,int base,int offset){
        this.pcb = new PCB(father,processID,base,offset);
        this.CPUTimeZone=CPUTimeZone;
        this.IOTimeZone=IOTimeZone;
        this.totalTimeZone=CPUTimeZone+IOTimeZone;
        this.processWork=workUnitList;
    }
    public boolean wait(String semaphoreName) {
        Semaphore semaphore = ProcessSystem.semaphoreHashMap.get(semaphoreName);
        if (semaphore.getValue() > 0) {
            semaphore.valueReduce();
            return true;
        } else {
            semaphore.valueReduce();
            semaphore.linkNewProcess(this);
            return false;
        }
    }

    public void run() {

    }

    public PCB getPcb() {
        return pcb;
    }

    public int getIOTimeZone() {
        return IOTimeZone;
    }

    public void setPcb(PCB pcb) {
        this.pcb = pcb;
    }

    public void setIOTimeZone(int IOTimeZone) {
        this.IOTimeZone = IOTimeZone;
    }

    public void setCPUTimeZone(int CPUTimeZone) {
        this.CPUTimeZone = CPUTimeZone;
    }

    public void setTotalTimeZone(int totalTimeZone) {
        this.totalTimeZone = totalTimeZone;
    }

    public void setProgressCount(int progressCount) {
        this.progressCount = progressCount;
    }

    public void setProcessWork(List<WorkUnit> processWork) {
        this.processWork = processWork;
    }

    public int getCPUTimeZone() {
        return CPUTimeZone;
    }

    public int getTotalTimeZone() {
        return totalTimeZone;
    }

    public int getProgressCount() {
        return progressCount;
    }

    public List<WorkUnit> getProcessWork() {
        return processWork;
    }

    public PCB getPCB() {
        return pcb;
    }
}
